/*
 * Copyright 2009 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.splink.deepsplink.boot {
	import org.splink.deepsplink.config.ConfigDataReader;
	import org.splink.library.distributor.Distributor;
	import org.splink.library.queue.IQable;
	import org.splink.library.queue.QEvent;

	import flash.utils.getQualifiedClassName;

	/**
	 * Bootstrapper for the deepsplink framework, which uses pure xml.
	 * It converts the xml to a configuration data model and initializes the 
	 * framework by invoking <code>Bootstrapper</code> with the given 
	 * <code>IDeepsplinkBootstrapStrategy</code>.
	 * 
	 * @author Max Kugland
	 */
	final public class XmlConfigBootstrapper extends Distributor implements IQable {
		private var _strategy : IBootStrategy;
		private var _xml : XML;

		public function XmlConfigBootstrapper(xml : XML, strategy : IBootStrategy) {
			_xml = xml;
			_strategy = strategy;
		}

		/**
		 * @inheritDoc
		 */
		public function get id() : String {
			return getQualifiedClassName(XmlConfigBootstrapper);
		}

		/**
		 * @inheritDoc
		 */
		public function start() : void {
			var reader : ConfigDataReader = new ConfigDataReader(_xml);
			new Bootstrapper(reader.read(), _strategy);
			distribute(new QEvent(this, QEvent.COMPLETE, id));
		}

		/**
		 * @inheritDoc
		 */
		public function stop() : void {
		}

		/**
		 * @inheritDoc
		 */
		public function reset() : void {
		}
	}
}
